#ifndef __OLED_H_
#define __OLED_H_	

//#include "stdint.h"
//#include "i2c.h"
#include "main.h"
#include "spi.h"
#include "gpio.h"
#include "oledfont.h"
#include <string.h>

/* < ------------------------------ 宏定义 ------------------------------> */

/* <写命令> */
#define OLED_CMD 0
/* <写数据> */
#define OLED_DAT 1

/* <移植需要修改SPI句柄> */
#define OLED_SPI hspi1

/* <数据/命令引脚(OLED的D/C引脚, 使用PA4)> */
#define Data_Cmd_Pin 				GPIO_PIN_1
#define Data_Cmd_GPIO_Port 	GPIOA

/* <复位脚(OLED的RST引脚, 使用PA6引脚)> */
#define OLED_RST_Pin 				GPIO_PIN_3
#define OLED_RST_GPIO_Port 	GPIOA

/* <拉高OLED的D/C引脚(拉低: 写入命令; 拉高: 写入数据)> */
#define Data_Cmd_State(level)	HAL_GPIO_WritePin(Data_Cmd_GPIO_Port, Data_Cmd_Pin, (GPIO_PinState)level)
#define OLED_RST_State(level)	HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, (GPIO_PinState)level)


#define OLED_CMD   0  //命令
#define OLED_DATA  1  //数据

#define NORMAL  0  //正常显示
#define REVERSE 1  //反显

#define NO_ALGIN 0  //不对齐
#define CEN_ALIGN 1 //水平居中对齐


//向设备写控制命令
void OLED_WR_CMD(uint8_t cmd);
//向设备写数据
void OLED_WR_DATA(uint8_t data);
//初始化oled屏幕
void OLED_Init(void);
//清屏size12 size16要清两行，其他函数有类似情况
void OLED_CLS(void);
//开启OLED显示    
void OLED_ON(void);
//关闭OLED显示     
void OLED_OFF(void);
void OLED_DrawBMP(uint8_t x0, uint8_t y0,uint8_t x1, uint8_t y1,uint8_t BMP[]);
void OLED_FILL(uint8_t BMP[]);	

uint8_t OLED_Display_Chinese(uint8_t x,uint8_t y,uint8_t w,uint8_t h,char *buff,uint8_t align);
uint8_t OLED_Display_String(uint8_t x,uint8_t y,uint8_t w,uint8_t h,char *str,uint8_t reverse,uint8_t align);
uint8_t OLED_Display_Char(uint8_t x,uint8_t y,uint8_t w,uint8_t h,char ch,uint8_t reverse,uint8_t align);
uint8_t OLED_Display_Image(uint8_t x,uint8_t y,uint8_t w,uint8_t h,char *img,uint8_t align);
#endif
